#include "accepterhandler.h"

#include "netlib.h"

namespace {

class Warp : public net::IAccepterHandler, public luabind::wrap_base {
public:
    virtual void OnAccept(net::ISocket* socket) {
        call<void>("OnAccept", socket);
    }
};

}

namespace kxlua {

AccepterHandler::AccepterHandler(NetLib* lib) {
    lib_ = lib;
    name_ = "AccepterHandler";
    isOpen_ = false;
}

AccepterHandler::~AccepterHandler() {
}

const std::string& AccepterHandler::GetName() const {
    return name_;
}

bool AccepterHandler::Open() {
    if (!isOpen_) {
        luabind::module(lib_->GetLua().GetState()) 
        [
            luabind::class_<net::IAccepterHandler, Warp>("AccepterHandler")
            .def(luabind::constructor<>())
            .def("OnAccept", &net::IAccepterHandler::OnAccept, &Warp::OnAccept)
        ];
        isOpen_ = true;
    }
    return true;
}

bool AccepterHandler::Close() {
}

}
